package com.polaris.live.viewmodel.luckybag

import androidx.lifecycle.MutableLiveData
import com.polaris.live.common.mvvm.viewmodel.BaseViewModel
import com.polaris.live.common.network.ApiResponse
import com.polaris.live.common.network.request
import com.polaris.live.common.network.state.ResultState
import com.polaris.live.net.chatService
import com.polaris.live.resp.back_resp.luckybag.LuckyBagDetailResp
import com.polaris.live.resp.base.ListResp
import com.polaris.live.widget.refresh.OnListListener

/**
 * LuckyBagHistoryViewModel
 *
 * @author Created by lucas on 2024/6/11 06:44
 */
class LuckyBagHistoryViewModel : BaseViewModel(), OnListListener {

    var mType: Int = 0

    val mListLiveData = MutableLiveData<ResultState<ListResp<Any>>>()

    override fun onRefresh() {
        getList(0)
    }

    override fun onLoadMore(pageIndex: Int) {
        getList(pageIndex)
    }

    private fun getList(pageIndex: Int) {
        request({
            if (mType == 0) {
                chatService.luckyBagReceiveList(pageIndex)
            } else {
                chatService.luckyBagSendList(pageIndex)
            } as ApiResponse<ListResp<Any>>
        }, mListLiveData)
    }

    //查看福袋详情
    val mDetailLuckyBagLiveData = MutableLiveData<ResultState<LuckyBagDetailResp>>()
    fun getLuckyBagDetail(luckyId: Long) {
        request({ chatService.luckyBagDetail(luckyId) }, mDetailLuckyBagLiveData)
    }
}